package com.hits.zzbzstart.service;

import com.hits.zzbzstart.entity.TGzRmcs;
import com.hits.zzbzstart.entity.TGzSx;
import com.hits.zzbzstart.entity.TGzSxCl;
import com.hits.zzbzstart.mapper.TDaimjbDao;
import com.hits.zzbzstart.mapper.TGzRmcsDao;
import com.hits.zzbzstart.mapper.TGzSxClDao;
import com.hits.zzbzstart.mapper.TGzSxDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangshen
 * @ClassName 初始化加载数据service
 * @Description TODO
 * @date 2020/12/22
 */
@Service
public class InitDataService {

    @Autowired
    private RedisTemplate redisTemplate; //redis操作模板

    @Autowired
    private TGzRmcsDao tGzRmcsDao; //使用地dao
    @Autowired
    private TDaimjbDao tDaimjbDao;//代码集dao
    @Autowired
    private TGzSxDao sxDao; //事项dao
    @Autowired
    private TGzSxClDao sxClDao; //事项材料dao
    @Value("${jgbm}")
    private String jgbm; //机构编码
    @Value("${jgdm}")
    private String jgdm; //机构代码

    public void initData() {
        //加载使用地信息
        List<TGzRmcs> areas = this.tGzRmcsDao.getAreaByJgbm(this.jgbm);
        if (areas == null || areas.size() == 0) {
            List<TGzRmcs> areasDmj = this.tDaimjbDao.getArea();
            this.redisTemplate.opsForList().rightPush("areas", areasDmj);
        } else {
            this.redisTemplate.opsForList().rightPush("areas", areas);
        }
        //加载事项信息
        List<TGzSx> sxList = this.sxDao.dataGrid(jgdm);
        sxList.forEach(e -> {
            //加载事项对应材料信息
            List<TGzSxCl> sxClList = this.sxClDao.getSxclById(e.getSxid(), jgdm);
            this.redisTemplate.opsForList().rightPush(e.getSxid(), sxClList);
        });
        this.redisTemplate.opsForList().rightPush("sxList", sxList);


    }


}
